package com.bob.web.service;

import com.bob.web.common.constant.Page;
import com.bob.web.dao.UserDao;
import com.bob.web.entity.system.Admin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Service;

/**
 * 名称: UserService<br>
 * 描述:<br>
 * 类型: JAVA<br>
 * 最近修改时间:2017/7/11 16:23<br>
 *
 * @author BoYangsh
 * @version [版本号, V1.0]
 * @since 2017/7/11 16:23
 */
//@Service
public class UserService {

	@Autowired
	private UserDao userDao;

	public Page<Admin> findPage(Page<Admin> page) {
		userDao.findPage(page);
		return page;
	}

	public void add(Admin user) {
		userDao.add(user);
	}

	public void delete(String id) {
		userDao.delete(id);
	}

	public void update(Admin user) {
		Query query = Query.query(Criteria.where("_id").is(user.getId()));
		Update update = Update.update("name", user.getName()).set("userName", user.getUsername()).set("gender",
				user.getGender()).set("age", user.getAge()).set("phone", user.getPhone()).set("email", user.getEmail())
				.set("address", user.getAddress());
		userDao.findAndModify(query, update);
	}

	public Admin findUserById(String id) {
		return userDao.findUserById(id);
	}
}
